package com.leetcode.LC;

public class LC26 {
    public int removeDuplicates(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }

        int length = 1, i, j = -1;
        for (i = 0; i < nums.length - 1; i++) {
            if (nums[i] != nums[i + 1]) {
                j++;
                nums[j] = nums[i];
                nums[j + 1] = nums[i + 1];
                length++;
            }
        }

        for (int num : nums) {
            System.out.print(num);
        }
        System.out.println();
        return length;
    }

    public int removeDuplicates_2(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        int size = 1;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] != nums[i + 1]) {
                nums[size] = nums[i + 1];
                size++;
            }
        }
        return size;
    }

    public int removeDuplicates_3(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        int p = 0, q = 1;
        for (; q < nums.length; q++) {
            if (nums[p] != nums[q]) {
                nums[p + 1] = nums[q];
                p++;
            }
            q++;
        }
        return p + 1;
    }

    public static void main(String[] args) {
        System.out.println(new LC26().removeDuplicates(new int[]{0, 0, 1, 1, 1, 2, 2, 3, 3, 4}));
    }
}
